package org.qqcui.designpattern.patterns.iterator;

import java.util.Iterator;

/**
 * 计算机学院
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/6 14:21
 **/
public class ComputeCollege implements College {

    /**
     * 使用数组存储专业信息
     */
    private Department[] departments;

    /**
     * 数据下标
     */
    private int index = 0;

    public ComputeCollege() {
        // 初始化5个专业
        this.departments = new Department[5];
        addDepartment("Java专业", "Java");
        addDepartment("PHP专业", "PHP");
        addDepartment("大数据专业", "大数据");
    }

    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        Department department = new Department(name, desc);
        departments[index] = department;
        index++;
    }

    @Override
    public Iterator createIterator() {
        return new ComputeCollegeIterator(departments);
    }
}
